package com.chuan.it_market.controller.buyer_controller;

import com.chuan.it_market.controller.BaseController;
import com.chuan.it_market.pojo.dto.ResponseDTO;
import com.chuan.it_market.pojo.entity.Goods;
import com.chuan.it_market.pojo.entity.GoodsType;
import com.chuan.it_market.pojo.entity.Seller;
import com.chuan.it_market.pojo.entity.ShopCar;
import com.chuan.it_market.pojo.vo.GoodsVO;
import com.chuan.it_market.service.GoodsService;
import com.chuan.it_market.service.SellerService;
import com.chuan.it_market.service.ShopCarService;
import com.chuan.it_market.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/buyer/goods")
public class GoodsController2 extends BaseController {
    @Resource
    GoodsService goodsService;
    @Resource
    TypeService typeService;
    @Resource
    ShopCarService shopCarService;
    @Resource
    SellerService sellerService;

    //买家进入购物界面前 需要把所有商品类型和商品全部查出来
    @RequestMapping("goodsList")
    String buyerGoodsList(Model model){
        List<GoodsType> alltype=typeService.selectAllType();
        model.addAttribute("alltype",alltype);
        List<GoodsVO> allgoods=goodsService.selectAllGoods();
        model.addAttribute("allgoods",allgoods);
        return "/buyer/goods/goods-list";
    }

    //买家商品详情页
    @RequestMapping("goodsDetail/{gno}")
    String goodsDetail(@PathVariable Integer gno, Model model){
        GoodsVO goodsVO =goodsService.getGoodsVODtetail(gno);

        model.addAttribute("goods",goodsVO);
        return "buyer/goods/goods-detail";
    }

    @RequestMapping("getGoodsByTno/{typeno}")
    @ResponseBody
    ResponseDTO getGoodsByTno(@PathVariable Integer typeno){

        List<GoodsVO> goodsVOS=goodsService.getGoodsVOSByTno(typeno);
        return ResponseDTO.ok("查询成功",goodsVOS);
    }

    @RequestMapping("queryByInput")
    @ResponseBody
    ResponseDTO queryByInput2(String name){


        List<GoodsVO> goodsList2=goodsService.getGoodsByInput2(name);
        return ResponseDTO.ok("查询成功",goodsList2);
    }


}
